#include "BMouseZoomImage.h"
#include <QDebug>

BMouseZoomImage::BMouseZoomImage(QWidget *parent)
    : QWidget(parent)
{
}

BMouseZoomImage::BMouseZoomImage(const QPixmap &pixmap, QWidget *parent) :
    QWidget(parent), m_pixmap(pixmap)
{
    QHBoxLayout* hLayout = new QHBoxLayout(this);
    m_label = new QLabel(this);
    //设置label属性
    m_label->setAlignment(Qt::AlignCenter);
    hLayout->addWidget(m_label);
    this->setLayout(hLayout);

    m_label->setPixmap(m_pixmap);
    this->resize(700, 500);
}

BMouseZoomImage::~BMouseZoomImage()
{
}

void BMouseZoomImage::wheelEvent(QWheelEvent *event)
{
    if ( QPoint(0, 120) == event->angleDelta() ) {
        if (m_scale < 3.0)  //上线2.0
            m_scale += 0.1;
    }
    else
        if (m_scale >= 0.2)
            m_scale -= 0.1; //下限0.1
    QPixmap pixmap = m_pixmap.scaled(m_pixmap.size() * m_scale,
                                     Qt::AspectRatioMode::KeepAspectRatio,
                                     Qt::TransformationMode::SmoothTransformation);
    m_label->setPixmap(pixmap);
}



